<?php


namespace app\app\controller;


use app\common\controller\All;
use think\exception\HttpResponseException;
use think\Response;

class Base extends All
{
    private $iv = 'c242519d86950b94';
    private $key = "75125dbd26b8d160";

    public function __construct()
    {
        parent::__construct();

//            $action = request()->action();
//            $system_type = input('system_type');
//            if($system_type !=='ios' && !in_array(strtolower($action),['showmap'])){
//                exit;
//            }
        $config = $GLOBALS['config']['site'];
        $this->assign($config);
        //站点关闭中
        if ($config['site_status'] == 0) {
            $this->error('站点已关闭');
        }
        if(!empty(input('app_id'))){
            $appInfos = db('banben')->cache('appinfos_app',3600)->column('appname','app_id');
            if(isset($appInfos[input('app_id')])){
                request()->post(['app_name'=>$appInfos[input('app_id')]]);
            }

        }
    }

    /**
     * @param string $msg
     * @param array $data
     * @param int $wait
     * @param array $header
     */
    public function success($msg = '', $data = [], $wait = 3, array $header = [])
    {
        $jiami = input('jiami', 1, 'intval');
        if ($jiami === 1) {
            $data = base64_encode(json_encode($data));
            //对data进行封装
            $data = base64_encode(openssl_encrypt($data, "AES-128-CBC", $this->key, true, $this->iv));
        }
        $type = 'json';
        $result = [
            'code' => 1,
            'msg' => $msg,
            'data' => $data,
            'wait' => $wait,
        ];


        $response = Response::create($result, $type)->header($header);

        throw new HttpResponseException($response);
    }
}